<script setup>
import {computed, inject, provide, ref, watch} from "vue";
import price from "@/api/logistics/price";
import BaseInfo from '@/views/logistics/price/components/baseinfo.vue'
import DateList from '@/views/logistics/price/components/datelist.vue'
import { auth, role } from '@/utils/common'
const record = ref({})

const crudRef = inject('crudRef')
const visible = ref(false)
const open = async (data) => {
  record.value = data
  refreshRecode()
  visible.value = true
}

const refreshRecode = async (type) => {
  if(record.value.id == undefined){
    return;
  }
  console.log('刷新详情')
  let request = await price.read(record.value.id)
  record.value = request.data
  if(type == true){
    console.log('刷新列表')
    crudRef.value.refresh()
  }
}

const colGap = ref(6)
const rowGap = ref(6)
provide('colGap', colGap)
provide('rowGap', rowGap)
provide('record', record)
provide('refreshRecode', refreshRecode)
defineExpose({ open,refreshRecode })
</script>
<template>
  <a-drawer v-model:visible="visible" width="80%" :footer="false" unmount-on-close>
    <template #title>
      <div class="grid grid-cols-[minmax(0,1fr),auto] items-center">
        <div>#{{ record.name }}</div>
      </div>
    </template>
      <a-space direction="vertical" class="w-full">
        <a-grid :cols="{ xs: 1, sm: 2, md: 3, lg: 4, xxl: 6 }" :colGap="colGap" :rowGap="rowGap">
          <base-info  />
          <date-list v-if="auth('logistics:priceDate:index')" />
        </a-grid>
      </a-space>
  </a-drawer>
</template>